/**
 * Created with JetBrains WebStorm.
 * User: Administrator
 * Date: 13-12-27
 * Time: 上午10:37
 * To change this template use File | Settings | File Templates.
 */
define(function(require,exports,module){
    var VERSION = "1.0",
        jQuery = $ =  require("jquery-1.8.2.min");
    var timer;
    var defaults = {
        event:'click',
        timeout:0,
        effect:'none',
        current:0,
        tabMenu:'.tabs',
        tabBox:'.frames',
        tabCurrent:'active',
        callback:null
    };

    function Tab(obj,option){
        this.targetElement = $(obj);
        this.options = $.extend(option,defaults);
        this.init();
    }
    Tab.prototype = {
        init:function(){
            var that = this,
                element = this.targetElement,
                options = this.options,

                tabMenu = element.children(options.tabMenu).children("li"),
                tabBox = element.children(options.tabBox).children(".frame"),

                current = element.data('current') || 0;

            tabMenu.bind(options.event,function(event){
                event.preventDefault();
                that.delay($(this),tabBox,options.timeout);
                if(options.callback){
                    options.callback(that);
                }
            });

        },
        tabHandle:function(elem,tabBox){
            elem.siblings("li").removeClass(this.options.tabCurrent).end()
                .addClass(this.options.tabCurrent);

            tabBox.siblings('div').addClass('hide').end()
                .eq(elem.index())
                .removeClass('hide');
        },
        delay:function(elem,tabBox,time){
            var that = this;
            time ? setTimeout(function(){
                that.tabHandle(elem,tabBox);
            },time) : that.tabHandle(elem,tabBox);
        },

        destroy:function(){

        },

        setOption:function(key,value){

        }
    };
    return Tab;
});